<template>
  <div class="con" v-loading="loading">
      <div class="user">
         <div class="title"> 
             <div class="search"  style="position: relative;">
                 <el-input v-model="viscon"  placeholder="回访内容 " size="small"></el-input>
                  <i class="el-icon-search" @click="getCusInfo()" style="position: absolute; width:40px;height:32px;right:0;top:0;color:#409EFF;text-align:center;line-height:32px"></i>
             </div>
                <i class="icon icon-wuuiconxiangjifangda searBtn" @click="fnShowModel()"></i>
         </div>
         <div class="list">
             <div class="info">
                <el-row>
                    <el-col :span="6">
                        <i class="icon icon-mingpian"></i>
                        <span>{{cusModel.CNName}}</span>
                    </el-col>
                    <el-col :span="12">
                        <i class="icon icon-shouji"></i>
                        <span>{{cusModel.Tel}}</span>
                    </el-col>
                    <el-col :span="6">
                        <i class="icon icon-xingbie"></i>
                        <span v-if="cusModel.Gender==1">男</span>
                        <span v-else>男</span>
                    </el-col>
                </el-row>
             </div>
             <el-tabs type="border-card">
                <el-tab-pane label="回访">
                  <div style="">
                    <div class="item" v-for="item in hVisit" :key="item.ID">
                        <div class="row">
                            <span>回访人</span>
                            <span class="gray">{{item.CustomerName}}</span>
                            <span>回访时间</span>
                            <span class="gray">{{item.Visit_Time}}</span>
                        </div>
                        <div class="row clearfix">
                            <div class="left">
                                <span>回访内容</span>
                            </div>
                            <div class="right gray">
                                {{item.Visit_Content}}
                            </div>
                        </div>
                    </div>
                  </div>
                </el-tab-pane>
                <el-tab-pane label="到访">
                    <div class="item" v-for="item in dVisit" :key="item.ID">
                        <div class="row">
                            <span>到访人</span>
                            <span class="gray">{{item.CustomerName}}</span>
                            <span>到访时间</span>
                            <span class="gray">{{item.Visit_Time}}</span>
                        </div>
                        <div class="row clearfix">
                            <div class="left ">
                                <span>项目名称</span>
                            </div>
                            <div class="right gray">
                                {{item.ProjectName}}
                            </div>
                        </div>
                    </div>
                </el-tab-pane>
            </el-tabs>
         </div>
      </div>
                    
      <div class="model"  v-show="showModel">
          <div class="prop">
              <span>回访内容:</span>
              <el-input
                type="textarea"
                :rows="3"
                placeholder="请输入内容"
                v-model="textarea">
            </el-input>
            <div class="rows">
                <el-button @click="fnCancel()" size="mini">清空</el-button>
                <el-button @click="fnSub()" type="primary" size="mini">确定</el-button>
            </div>
          </div>
      </div>
  </div>
</template>
<script>
import Api from "../../kites/api";
export default {
  name: "Customer",
  data() {
    return {
      loading: false,
      textarea: "",
      datas: [],
      cusModel: {}, //客户实体
      dvlength: "",
      hvDate: "", //回访时间,目前没用
      dVisit: [], //到访列表
      hVisit: [], //回访列表
      showModel: false,
      viscon:''
    };
  },
  mounted() {
    this.getcusmodel(); //获取客户实体
    this.getsalevisit(); //回访
    this.getcstvisit(); //到访
  },
  methods: {
    //获取客户实体
    getcusmodel() {
      var me = this;
      this.$axios.get(Api.getcusmodel + "/" + me.$route.params.id).then(res => {
        if (res.data.isOK) {
          me.cusModel = res.data.data;
          
        } else {
          if (res.data.msg == "Token无效" || res.data.msg == "Token缺失") {
            me.$router.push("/Login");
          } else {
            me.$message.error(res.data.msg);
          }
        }
      });
    },
    //获取客户回访列表
    getsalevisit() {
      var me = this;
      me.loading = true;
      this.$axios
        .post(Api.getsalevisit, {
          Para: {
            CustomerID:  me.$route.params.id,
            Key: me.viscon
          },
          PageSize: 8,
          PageIndex: 0,
          OrderbyString: "SalesName"
        })
        .then(res => {
          if (res.data.isOK) {
            me.loading = false;
            me.hVisit = res.data.data.Data;
          } else {
            if (res.data.msg == "Token无效" || res.data.msg == "Token缺失") {
              me.loading = false;
              me.$router.push("/Login");
            } else {
              me.loading = false;
              me.$message.error(res.data.msg);
            }
          }
        });
    },

    //获取客户到访列表
    getcstvisit() {
      var me = this;
      this.$axios
        .post(Api.getcstvisit, {
          Para: me.$route.params.id,
          PageSize: 10,
          PageIndex: 0,
          OrderbyString: "SalesName"
        })
        .then(res => {
          if (res.data.isOK) {
            me.dVisit = res.data.data.Data;
          } else {
            if (res.data.msg == "Token无效" || res.data.msg == "Token缺失") {
              me.$router.push("/Login");
            } else {
              me.$message.error(res.data.msg);
            }
          }
        });
    },
    //设置客户回访信息
    salesvisit() {
      var me = this;
      me.loading = true;
      this.$axios
        .post(Api.salesvisit, {
          ID: "",
          SalerID: me.cusModel.SalerID,
          CustomerID: me.cusModel.ID,
          Visit_Time: "",
          Visit_Content: me.textarea,
          CreateMan: "",
          CreateDate: ""
        })
        .then(res => {
          if (res.data.isOK) {
            me.loading = false;
            me.datas = res.data.data.Data;
            me.getsalevisit();
          } else {
            if (res.data.msg == "Token无效" || res.data.msg == "Token缺失") {
              me.$router.push("/Login");
            } else {
              me.loading = false;
              me.$message.error(res.data.msg);
            }
          }
        });
    },

    fnShowModel() {
      this.showModel = true;
    },
    //取消
    fnCancel() {
      this.showModel = false;
    },
    //根据回访内容搜索列表
    getCusInfo() {
      this.getsalevisit();
    },
    //确认
    fnSub() {
      this.showModel = false;
      this.salesvisit();
    },
  }
};
</script>
<style scoped>
a {
  text-decoration: none;
}
.con {
  position: relative;
  width: 100%;
  height: 100%;
}
.topnav {
  width: 100%;
  height: 45px;
  background-color: #35495e;
  line-height: 45px;
  color: #ffffff;
}
.topnav i {
  font-size: 25px;
  vertical-align: middle;
}
.topnav span {
  display: inline-block;
  height: 100%;
}
.user {
  width: 100%;
  /* height: calc(100% - 1px); */
}
.user .title {
  position: fixed;
  padding-top: 0.5rem;
  padding-left: 0.5rem;
  padding-right: 0.5rem;
  top: 0;
  left: 0;
  width: 100%;
  height: 3.2rem;
  z-index: 1000;
  border: 1px solid #e6ebf5;
  background-color: #fbf9fe;
}
.user .search {
  display: inline-block;
  width: 80%;
  float: left;
}
.user .searBtn {
  width: 10%;
}
.user .down {
  width: 10%;
}
.user .title i {
  font-size: 1.5rem;
  /* float: right; */
  /* margin-left: 1rem; */
  line-height: 2.6rem;
}

.list {
  /* margin-bottom: 4.2rem; */
  margin-top: 4rem;
  /* padding: 0.5rem; */
}
.list .info {
  line-height: 2.5rem;
  border-bottom: 1px solid #cfdbe2;
  margin-bottom: 10px;
  font-size: 1.2rem;
}
.list .item {
  border: 1px solid #cfdbe2;
  border-top-width: 3px;
  border-radius: 0.5rem;
  margin-top: 0.5rem;
  padding: 0.5rem;
  font-size: 1.2rem;
}
.list .item span {
  text-align: left;
  margin-right: 1rem;
}
.left {
  display: inline-block;
  float: left;
  width: 25%;
}
.right {
  float: right;
  width: 74%;
  text-align: left;
  word-wrap: break-word;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  overflow: hidden;
}
.row {
  text-align: left;
  margin-bottom: 1rem;
}


.gray {
  color: #999;
}

.clearfix:after {
  content: ".";
  width: 0;
  height: 0;
  visibility: hidden;
  display: block;
  clear: both;
  overflow: hidden;
}

.model {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.2);
}
.model .prop {
  width: 95%;
  background: #ffffff;
  margin: auto;
  border-radius: 0.5rem;
  margin-top: 1rem;
  padding: 1rem 0;
}
.model .prop span {
  float: left;
  font-size: 1.2rem;
  margin-left: 1.5rem;
}
.model .prop .rows {
  height: 2.5rem;
  padding: 0 1rem;
  margin-top: 1rem;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  -webkit-user-select: none;
  outline: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-tap-highlight-color: transparent;
}
.el-textarea {
  margin-top: 1rem;
  width: 90%;
}

.clearfix:after {
  content: ".";
  width: 0;
  height: 0;
  visibility: hidden;
  display: block;
  clear: both;
  overflow: hidden;
}
</style>



